package com.example.datatrans.bean;

import io.swagger.annotations.ApiModelProperty;

/**
 *
 *  响应实体
 * @author: caoshi
 * @date: 2022/5/19 10:17
 */
public class ResponseResult<T> {

    @ApiModelProperty("响应码")
    private Integer code;       // 响应码

    @ApiModelProperty("信息")
    private String msg;         // 成功信息

    @ApiModelProperty("响应数据")
    private T data;        // 数据


    public ResponseResult() {

    }

    public Integer getCode() {
        return this.code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return this.msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return this.data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public ResponseResult(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /**
     *  返回成功
     * @return
     */
    public static <T> ResponseResult<T> success() {
        return new ResponseResult<>(ResultCodeEnum.SUCCESS.getRet(), "success", null);
    }


    /**
     *  返回成功数据
     * @param data
     * @return
     */
    public static <T> ResponseResult<T> success(T data) {
        return new ResponseResult<>(ResultCodeEnum.SUCCESS.getRet(), "success", data);
    }

    /**
     *  返回成功数据和信息
     * @param data
     * @return
     */
    public static <T> ResponseResult<T> success(String msg, T data) {
        return new ResponseResult<>(ResultCodeEnum.SUCCESS.getRet(), msg, data);
    }

    /**
     * 返回失败响应码和信息
     * @param code
     * @param emsg
     * @return
     */
    public static <T> ResponseResult<T> fail(int code, String emsg) {
        return new ResponseResult<>(code, emsg, null);
    }


    /**
     * 返回失败响应码和信息
     * @param
     * @param emsg
     * @return
     */
    public static <T> ResponseResult<T> fail(String emsg) {
        return new ResponseResult<>(ResultCodeEnum.INTERNAL_SERVER_ERROR.getRet(), emsg, null);
    }


    /**
     *
     * @param data
     * @return
     */
    public ResponseResult<T> data(T data) {
        this.data = data;
        return this;
    }


}
